//Problem Id:1017  User Id:tq 
//Memory:92K  Time:406MS
//Language:C++  Result:Accepted

/*	author: TangQiao @ Wind 
	problem name: Humble Numbers
	source : ULM 1996

	problem type: 数学题 || 搜索题 || 自己想算法题
	problem description: 如果一个数的质因数只由2,3,5,7构成的话,此数就为Humble Number,求20亿之内的所有这种数
			     输入这种数的NO.输出这个数.
	problem solution: 搜索,事先求出2,3,5,7的0~30次方.相关代码: double n2[MAX],n3[MAX],n5[MAX],n7[MAX]; 及init函数.			  
		       
	award & note :  题目本来不难,可以我却错了5次,原来是输出格式上的一点问题.以11为尾数的应该输出th,包括111在内,而
			我原来的程序却只是把11后面加th.在12,13上,我也范了同样的错误.
			
	another solution: 也可以用这样的算法生成:
			  将1放入队列中,每次元素出队,分别乘以2,3,5,7找出最小的进入答案数组和队列,
			  循环这样操作,直到找到第5842个元素为止.(因为由题目例子中20亿正好是第5842个元素)
	date : 2005.5.20 北师大校队个人选拨赛2
	
*/

#include <stdio.h>
#include <string.h>
#include <iomanip.h>
#include <iostream.h>
#include <math.h>
#define MAX 33
#define TOU 2000000001

double n2[MAX],n3[MAX],n5[MAX],n7[MAX];

double shu[20000];
int tot;

void tsort()
{
	int i,j;
	double t;
	for (i=1;i<tot;i++)
		for (j=i+1;j<=tot;j++)
			if (shu[i]>shu[j])
			{
				t=shu[i];
				shu[i]=shu[j];
				shu[j]=t;
			}
}




void init()
{
	int i;
	double a;
	a=1;
	for (i=0;i<=31;i++)
	{
		n2[i]=a;
		a*=2;
	}
	a=1;
	for (i=0;i<=31;i++)
	{
		n3[i]=a;
		a*=3;
	}
	a=1;
	for (i=0;i<=31;i++)
	{
		n5[i]=a;
		a*=5;
	}
	a=1;
	for (i=0;i<=31;i++)
	{
		n7[i]=a;
		a*=7;
	}
}


main()
{
	

	int tt[10];
	char outs1[100],outs2[100],outs3[100];
	int pt;
	int i;
	double count,a,b,c,d;
	
	init();
	shu[1]=1;
	tot=0;
	tt[1]=-1;
	pt=1;
	while (pt>0)
	{
		tt[pt]++;
		if (pt>4)
		{
//			for (i=1;i<=4;i++) printf("%d ",tt[i]);
//			printf("\n");
			a=n2[tt[1]];
			b=n3[tt[2]];
			c=n5[tt[3]];
			d=n7[tt[4]];
			count=a*b*c*d;
			if (a<TOU && b<TOU && c<TOU && d<TOU && count<TOU)
			{				
				shu[++tot]=count;
		//		printf("No.%d %lf\n",tot, count);
			}	
			pt--;

		}
		else if (tt[pt]>30)
		{
			pt--;
		}
		else
		{
			pt++;
			tt[pt]=-1;
		}

	}//end of while 

	tsort();
	int n;
	int ff;
	while (1)
	{
		cin>>n;
		if (n==0) break;
		strcpy(outs1,"");
		i=n%10;
		ff=n%100;
		sprintf(outs1,"The %d",n);
		if      (ff==11||ff==12||ff==13) sprintf(outs2,"th");		
		else if (i==1) sprintf(outs2,"st");
		else if (i==2) sprintf(outs2,"nd");
		else if (i==3) sprintf(outs2,"rd");
		else sprintf(outs2,"th");
		
		//printf(" humble number is ");
		sprintf(outs3," humble number is %.0lf.",shu[n]);
		printf("%s%s%s\n",outs1,outs2,outs3);
	
	}


	return 0;
}

